﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 循环的嵌套01
{
    class Program
    {
        static void Main(string[] args)
        {

            // 需求
            /* 1
             * 12
             * 123
             * 1234
             * 12345
             * 1234
             * 123
             * 12
             * 1
             *
             */

            // 控制行数，i代表行数
            for (int i = 1; i <= 5; i++)
            {
                // 控制打印数字的个数，j代表打印的数字
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }

            /* 12345
             * 1234
             * 123
             * 12
             * 1
             */
            for (int i = 1; i <= 5; i++)
            {
                for (int j = 1; j <= 5 - i + 1; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }


            /* 54321
             * 4321
             * 321
             * 21
             * 1
             */
            for (int i = 1; i <= 5; i++)                    //...
            {
                for (int j = 5 - i + 1; j >=1; j--)         //....
                {
                    Console.Write(j);                       //
                }                                           //
                Console.WriteLine();
            }

            /*     1
             *    12
             *   123
             *  1234
             * 12345
             */
            //控制行数，i代表行数
            for (int i = 1; i <= 5; i++)
            {
                //控制打印空格
                for (int j = 1; j <= 5 - i; j++)
                {
                    Console.Write(" ");
                }
                //控制打印数字
                for (int k = 1; k <= i; k++)
                {
                    Console.Write(k);
                }
                Console.WriteLine();
            }


            /*     1
             *    21
             *   321
             *  4321
             * 54321
             */
            //控制行数，i代表行数
            for (int i = 1; i <= 5; i++)
            {
                //控制打印空格
                for (int j = 1; j <= 5 - i; j++)
                {
                    Console.Write(" ");
                }
                //控制打印数字
                for (int k = i; k >= 1; k--)
                {
                    Console.Write(k);
                }
                Console.WriteLine();
            }

            /* 1 * 1 = 1
             * 1 * 2 = 2    2 * 2 = 4
             * 1 * 3 = 3    2 * 3 = 6   3 * 3 = 9 
             * 1 * 4 = 4    2 * 4 = 8   3 * 4 = 12  4 * 4 = 16
             * 1 * 5 = 5    2 * 5 = 10  3 * 5 = 15  4 * 5 = 20  5 * 5 = 25
             * 
             * 
             */

            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("{0}*{1}={2}\t", j, i, i * j);
                }
                Console.WriteLine();
            }
        }
    }
}
